package com.compass.doctor.ui.home.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import com.compass.doctor.R
import com.compass.doctor.callback.OnCustomButtonClick
import com.compass.doctor.databinding.LayoutCareImplementedItemBinding
import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseRecyclerViewAdapter
import com.compass.framework.ext.onClick
import com.compass.framework.glide.setUrl
import com.compass.framework.glide.setUrlCircle
import com.compass.framework.manager.DictionariesManager
import com.compass.framework.manager.UserInfoManager
import com.compass.framework.model.MedicalCareOrder
import com.compass.framework.utils.DateUtils
import com.compass.framework.utils.ViewUtils
import com.compass.framework.utils.dpToPx
import com.compass.framework.utils.getDrawableResource

/**
 * Description： 待执行
 * Date:2023/12/11 21:14
 */
class CareImplementedAdapter : BaseRecyclerViewAdapter<MedicalCareOrder, LayoutCareImplementedItemBinding>() {
    private lateinit var onCustomItemClick :OnCustomButtonClick


    fun setOnCustomItemClick(onCustomItemClick :OnCustomButtonClick){
        this.onCustomItemClick=onCustomItemClick
    }

    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<LayoutCareImplementedItemBinding>,
        item: MedicalCareOrder?,
        position: Int
    ) {
        if (item == null) return
        holder.binding.apply {
            //{"label":"出发","value":"3"},{"label":"到达","value":"4"},{"label":"完成","value":"5"}
            tvType.text = if (UserInfoManager.getUserType() == "1") "医" else "护"
            ViewUtils.setClipViewCornerRadius(imgMap, dpToPx(5))
            imgMap.setUrl(item.locationUrl)
            tvTitle.text = item.nurseName
            tvDepart.text = item.etd
            tvVisitTime.text=DateUtils.conversionTime(item.appointmentTime,DateUtils.FORMAT_TWO)
            item.address?.let {     tvAddress.text=it.address}
            tvLocation.text="${item.distance}km"
            tvName.text=item.patientName
            ivHead.setUrlCircle(item.patientAvatar)
            ivSex.background= if (item.patientSex==1) getDrawableResource(R.mipmap.icon_male) else  getDrawableResource(
                R.mipmap.icon_female)
            tvAge.text = item.patientAge
            ViewUtils.setClipViewCornerRadius(imgMask, dpToPx(5))
            tvStatus.text=DictionariesManager.getNurseStatusValue(item.status)
            when(item.status){
                "3"->{
                    tvClinicalReception.text="出发"
                    tvClinicalReception.background= getDrawableResource(R.drawable.btn_shape_orange_5)
                }
                "4"->{
                    tvClinicalReception.text="到达"
                    tvClinicalReception.background= getDrawableResource(R.drawable.btn_shape_blue_5)
                }
                "5"->{
                    tvClinicalReception.text="完成"
                    tvClinicalReception.background= getDrawableResource(R.drawable.btn_shape_green_5)
                }
            }

            tvContactPatient.onClick {
                onCustomItemClick.onButtonCallBack(position,"phone")
            }
            tvContactOnline.onClick {
                onCustomItemClick.onButtonCallBack(position,"message")
            }
            tvClinicalReception.onClick {
                onCustomItemClick.onButtonCallBack(position,"dialog")
            }
        }
    }

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): LayoutCareImplementedItemBinding {
        return LayoutCareImplementedItemBinding.inflate(layoutInflater, parent, false)
    }
}